#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/21 0021 12:49
# @Author  : Arliki
# @File    : tcp_client.py
import socket
import time
from multiprocessing import Process


def run():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('127.0.0.1', 9999))
    print(s.recv(1024).decode('utf-8'))
    a = '张三'
    c = '李四'
    for i in [b'tom', a.encode('utf-8'), c.encode('utf-8')]:
        s.send(i)
        print(s.recv(1024).decode('utf-8'))
    for i in [b'toms', a.encode('utf-8'), c.encode('utf-8')]:
        s.send(i)
        print(s.recv(1024).decode('utf-8'))
        time.sleep(1)
    s.send(b'exit')
    s.close()
    print('close connect')


def run_udp():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    a = '张三'
    c = '李四'
    for i in [b'tom', a.encode('utf-8'), c.encode('utf-8')]:
        s.sendto(i, ('127.0.0.1', 9999))
        print(s.recv(1024).decode('utf-8'))
    s.close()


if __name__ == '__main__':
    # w=[]
    # for _ in range(5):
    #     w.append(Process(target=run))
    # for i in w:
    #     i.start()
    # for i in w:
    #     print("%s is join "%i)
    #     i.join()
    # print("is ok ")
    run_udp()
